<template>
	<view>

		<!-- 	<cu-custom bgImage="https://image.weilanwl.com/color2.0/plugin/sylb2244.jpg" @tap='isbaks'  :isBack="true">
			<text >返回</text>
			<block slot="content">订单信息</block>
		</cu-custom> -->

		<view class="cu-bar bg-white  solid-bottom">

			<view @tap='isbaks' class="cuIcon-back " style="font-size: 20px;"></view>
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" placeholder="输入搜索的关键词" confirm-type="search" @input="searchIcon"></input>
			</view>

		</view>


		<scroll-view scroll-x class="bg-white nav">
			<view class="flex text-center">
				<view class="cu-item flex-sub " :class="index==TabCur?'text-orange cur':''" v-for="(item,index) in nva"
					:key="index" @tap="tabSelect" :data-id="index">
					{{item.name}}



				</view>
			</view>
		</scroll-view>

		<block v-for="(item1,index1) in authlist" :key="index1">
			<view class="bg-white radius margin-top" style="border-radius: 10px;" v-if="TabCur==0">
				<view class="cu-bar bg-white solid-bottom margin-top" @tap="encryauth" :data-name='item1.authorderdetails[0].authname' :data-auth='item1.authorderdetails[0].encry'>
					<view class="action" style="width: 100%;">
						<text class="cuIcon-title text-orange " style="margin-left: -5%;"></text><text>点产品查看授权码</text>
						<text style="color: limegreen;margin-left: 50%;" v-if="item1.paytype==0">已完成</text>
						<text style="color: red;margin-left: 50%;" v-else>未支付</text>
					</view>
				</view>


				<view class="cu-list menu-avatar">
					<block v-for="(item,index) in item1.authorderdetails" :key="index">
						<view class="cu-item" @tap="encryauth" :data-name='item.authname' :data-auth='item.encry'
							:data-sn='item.sn'>
							
							<view class="cu-avatar radius lg"
								:style="[{'background-image':'url('+item.authlist.urlimage+')'}]"></view>
							<view class="content">
								<view class="text-grey">{{item.authname}}</view>
								<view class="text-gray text-sm flex">
									<view class="text-gray text-sm flex">
										<text class="text-cut">{{item.authlist.authdesc}}</text>

									</view>
								</view>
							</view>
							<view class="action">
								<view class="text-grey text-xs">x{{item.devicenum}}</view>
								<view class="cu-tag round bg-red sm">{{item.price}}¥</view>
							</view>
						</view>

					</block>
				</view>

				<view class="cu-bar" style="font-weight:bold"><text
						style="padding-left:1%;">{{item1.createDate.time|formatDate}}</text> <text
						style="color: #CCCCCC;padding-left: 20%;">总价¥{{item1.total}}</text><text
						style="margin-right: 2%;">实付款¥{{item1.realtotal}}</text>
				</view>
			</view>
		</block>

		<uni-load-more :status="status" :size="20" :content-text="contentText" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				TabCur: 0,
				scrollLeft: 0,
				nva: [{
						name: '全部'
					},
					{
						name: '待收货'
					},
					{
						name: '待评价'
					},
					{
						name: '排行'
					}
				],
				authlist: [],
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
				},
				page: 1,
				rows: 10,
				reload: false //是否重新加载
			}
		},
		filters: {
			formatDate: function(value) {
				let date = new Date(value);
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM;
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d;
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h;
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m;
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s;
				return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
			}


		},
		onReachBottom() {
			if (this.status == 'noMore') return
			this.status = 'loading';
			this.authorder();
		},

		onLoad() {
			this.checkUserInfo();
			this.authorder();

			console.log("openid" + getApp().globalData.openid)

		},
		onBackPress() {
			alert("返回");
		},
		methods: {
			checkUserInfo() {
				var that = this
				uni.getStorage({
					key: 'userinfo',
					success: function(res) {},
					fail() {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}
				})
			},
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
			},
			authorder() {
				uni.request({
					url: this.$constant.BASEURL + this.$constant.GET_queryorder,
					method: "POST",
					data: {
						page: this.page, //页码 1
						rows: this.rows, //每页数 10
						openid: getApp().globalData.openid,
						username: getApp().globalData.username,
						token: getApp().globalData.token,
						rec: 2
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					complete: (res) => {
						//console.log( JSON.stringify(res.data))
						let page = res.data.data
						//console.log(page)
						if (typeof(page) == 'undefined') return
						//console.log(page)
						if (page.page * page.rows >= page.total) {
							this.status = 'noMore';
						}
						if (res.data.code == 0) {
							let list = page.results
							this.authlist = this.reload ? list : this.authlist.concat(list)

							// alert(JSON.stringify(this.authlist[0]));
							// console.log(JSON.stringify(this.authlist[0]))
							this.page++;
							this.reload = false;
							// console.log(list)
						} else {
							uni.showModal({
								content: res.data.message,
								showCancel: false
							})
						}


					}
				});

			},

			encryauth(e) {
				console.log(e)
				//console.log(e.currentTarget.dataset)

				uni.navigateTo({
					url: 'encry?authname=' + e.currentTarget.dataset.name + '&auth=' + e.currentTarget.dataset.auth
				})

			},
			isbaks() {



				uni.switchTab({
					url: '../component/empinfo'
				});

			}

		}
	}


	// window.history.pushState(null,null,"#");

	// window.addEventListener("popstate",function(){



	// 	var url ="https://huaan.lsyat.com/yundianmao/auth/index.html";

	// 	location.href=url;

	// // uni.switchTab({
	// // 	url: '../component/empinfo'
	// // });

	// });
</script>

<style>

</style>